package com.yyfax.pay.console.service;

import javax.annotation.Resource;

import com.yyfax.pay.console.domain.ExceptionRecordDO;
import com.yyfax.pay.console.vo.OrderInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yyfax.framework.common.Log;
import com.yyfax.pay.common.enums.BusiTypeEnum;
import com.yyfax.pay.common.exception.PayException;
import com.yyfax.pay.common.exception.PayExceptionCode;
import com.yyfax.pay.console.vo.DealResultVO;
/**
 * 异常处理基类
 *
 * @author wangjwy
 * @date 2018/6/29 11:29
 * @since 2.2.3
 */
@Service
public abstract class CommonExceptionService {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private ExceptionRecordService exceptionRecordService;

    /**
     * 保存异常记录
     *
     * @author wangjwy
     * @date 2018/6/29 11:28
     * @since 2.2.3
     * @param record
     * @return void
     * @throws Exception
     */
    public void saveExceptionRecord(ExceptionRecordDO record) throws PayException {
        final String OP = "ExceptionService.saveExceptionRecord";
        try {
            exceptionRecordService.insert(record);
        } catch (Exception e) {
            logger.error(Log.op(OP).msg("保存异常记录失败").kv("exceptionRecordDO", record).toString(), e);
            throw PayExceptionCode.ERROR_OPT_FAIL.exp();
        }
    }

    /**
     * 通用异常处理
     *
     * @author wangjwy
     * @date 2018/6/29 11:31
     * @since 2.2.3
     * @param busiId, busiTypeEnum, expType
     * @return com.yyfax.pay.console.vo.DealResultVO<T>
     */
    public abstract DealResultVO dealException(String busiId, BusiTypeEnum busiTypeEnum, Integer expType);

    /**
     * 查询订单详情
     *
     * @author wangjwy
     * @date 2018/6/29 11:31
     * @since 2.2.3
     * @param busiId, busiTypeEnum, expType
     * @return com.yyfax.pay.console.vo.DealResultVO<T>
     */
    public abstract OrderInfoVO queryOrderInfo(String busiId);

}
